//! # Shuffle
//!
//! 实现了对数组的随机打乱
//!
//! 所有都是以 trait 形式实现
//!

use rand::{seq::SliceRandom, thread_rng};

mod head;
pub use head::*;

mod refer;
pub use refer::*;

/// 生成从 start..end 的随机打乱数列
///
/// 传入 (0, 10) 则会从 0~9 打乱
pub fn random_list(start: usize, end: usize) -> Vec<usize> {
    let mut rng = thread_rng();

    let mut list: Vec<usize> = (start..end).into_iter().collect();

    list.shuffle(&mut rng);

    list
}

#[macro_export]
/// 创建随机数列
///
/// 例如：传入 (0, 10) 则会从 0~9 打乱
macro_rules! random_list {
    ($start:expr => $end:expr) => {
        $crate::utils::shuffle::random_list($start, $end)
    };

    ($start:expr => +$end:expr) => {
        random_list!($start => $end + 1)
    };

    ($end:expr) => {
        random_list!(0 => $end)
    };

    (+$end:expr) => {
        random_list!(0 => $end + 1)
    };
}
